/**
 * 全局Getters - 提供跨模块的计算属性
 */

const getters = {
  user: (state) => state.user.user,
  isLoggedIn: (state) => state.user.isLoggedIn,
  currentUser: (state) => state.user.user,
  userDisplayName: (state) => {
    if (!state.user) return ''
    return state.user.user.name || state.user.user.userName || state.user.user.email
  },
  userAvatar: (state) => {
    if (!state.user.user || !state.user.user.avatar) {
      return '/default-avatar.png'
    }
    return state.user.user.avatar
  },
  userRoles: (state) => state.user.roles,

  // 导航菜单（从用户模块获取）
  navMenuItems: (state) => {
    if (!state.user.isLoggedIn) {
      // 未登录状态的导航栏 - 移除登录和注册按钮
      return [
        { name: '首页', path: '/', key: 'home' },
        { name: '宠物领养板块', path: '/adoption-browse', key: 'adoption' },
        { name: '宠物救助板块', path: '/rescues', key: 'rescues' },
        { name: '宠物交流论坛', path: '/forum', key: 'forum' }
      ]
    } else {
      // 普通用户登录后的导航栏
      return [
        { name: '首页', path: '/', key: 'home' },
        { name: '宠物领养浏览', path: '/adoption-browse', key: 'adoption-browse' },
        { name: '我的领养申请', path: '/my-applications', key: 'my-applications' },
        { name: '宠物救助信息', path: '/rescues', key: 'rescues' },
        { name: '我发布的救助', path: '/my-rescues', key: 'my-rescues' },
        { name: '宠物交流论坛', path: '/forum', key: 'forum' },
        { name: '我的收藏', path: '/forum/favorites', key: 'favorite-posts' },
        { name: '个人中心', path: '/profile', key: 'profile' }
      ]
    }
  }
}

export default getters